<script setup lang="ts">
import { ref } from 'vue'

const message = ref<string>('')

const emit = defineEmits<{
  (event: 'send', content: string): void
}>()

const send = (): void => {
  if (message.value.trim()) {
    emit('send', message.value)
    message.value = ''
  }
}

const handleKeyPress = (e: KeyboardEvent): void => {
  if (e.key === 'Enter' && !e.shiftKey) {
    e.preventDefault()
    send()
  }
}
</script>

<template>
  <div class="message-input-container">
    <div class="message-input">
      <textarea
        v-model="message"
        @keydown="handleKeyPress"
        placeholder="输入消息..."
        rows="3"
        class="input-area"
      ></textarea>
      <button @click="send" class="send-button">发送</button>
    </div>
  </div>
</template>

<style scoped>
.message-input-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px;
  background-color: #f8f9fa;
  border-top: 1px solid #e9ecef;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.message-input {
  display: flex;
  gap: 12px;
  max-width: 1200px;
  margin: 0 auto;
}

.input-area {
  flex: 1;
  padding: 12px;
  border: 1px solid #ced4da;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  transition: all 0.3s ease;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
  max-height: 150px;
  overflow-y: auto;
}

.input-area:focus {
  outline: none;
  border-color: #86b7fe;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.send-button {
  padding: 10px 20px;
  background-color: #0d6efd;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  height: fit-content;
  align-self: center;
}

.send-button:hover {
  background-color: #0b5ed7;
}

.send-button:active {
  background-color: #0a58ca;
  transform: scale(0.98);
}

.send-button:disabled {
  background-color: #6c757d;
  cursor: not-allowed;
  opacity: 0.65;
}
</style>
